#ifndef __THREADPOOL_H_
#define __THREADPOOL_H_
#include "KLib.h"
#include "NonCopyable.h"
#include "Task.h"
#include "Thread.h"
#include "EventList.h"
#include "ScopedLock.h"
SK


class ThreadPool : public NonCopyable
{
private:
    u32 numThreads;
    Thread *poolManager;

    Lock taskLock;
    typedef std::queue <Task *>TaskQueue;
    TaskQueue tasks;

    Lock threadLock;
    typedef Thread* pThread;
    pThread *threads;
    EventList *threadCompEvents;

    Task* getNextTask (void);
    Thread *getFreeThread (void);
    void run(void);
    void initThreads (void);
public:
    ThreadPool (u32 numThreads);
    ~ThreadPool ();

    void queueTask (Task *task);
    
    void start (void);
    static void _poolStart (void *pool);
};

EK
#endif